package taller2.view.menus.CreatorMenus;

import java.awt.Color;
import java.awt.GridBagLayout;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;

import taller2.controller.listeners.GraphCreator.GraphCreatorApplyChangesButtonListener;
import taller2.controller.listeners.GraphCreator.GraphCreatorLoadButtonListener;
import taller2.controller.listeners.GraphCreator.GraphCreatorMenuListener;
import taller2.controller.listeners.GraphCreator.GraphCreatorSaveButtonListener;
import taller2.controller.listeners.GraphCreator.GraphCreatorSizeListener;
import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.utils.Constants;
import taller2.utils.Utils;
import taller2.view.draws.DrawingArea;
import taller2.view.windows.CreatorWindows.GraphCreatorWindow;

public class GraphCreatorMenu extends JPanel{
	private static final long serialVersionUID = 1L;

	protected JComboBox<String> options;
	private JSlider sizeSelector;
	private JToggleButton applyChangesButton;
	private JToggleButton saveGraphButton;
	private JToggleButton loadGraphButton;
	
	// constructor
	public GraphCreatorMenu(DrawingArea area,Graph graph,GraphCreatorWindow window, AlgorithmApplicator algorithmApplicator){
		sizeSelector = new JSlider(10, 100);
		sizeSelector.addChangeListener(new GraphCreatorSizeListener(area));
		
		saveGraphButton = new JToggleButton("save");
		saveGraphButton.addActionListener(new GraphCreatorSaveButtonListener(window,this));
				
		loadGraphButton = new JToggleButton("load");
		loadGraphButton.addActionListener(new GraphCreatorLoadButtonListener(window,this));	
				
		createOptions(area,graph, algorithmApplicator);
				
		applyChangesButton = new JToggleButton("applyChanges");
		applyChangesButton.addActionListener(new GraphCreatorApplyChangesButtonListener(window,this));	

		setLayout(new GridBagLayout());
		
		Utils.addComponent(this,options,0.25,1,new taller2.utils.Point(0,0));
		Utils.addComponent(this,saveGraphButton,0.15,1,new taller2.utils.Point(1,0));
		Utils.addComponent(this,loadGraphButton,0.15,1,new taller2.utils.Point(2,0));		
		Utils.addComponent(this,applyChangesButton,0.15,1,new taller2.utils.Point(3,0));
		Utils.addComponent(this,sizeSelector,0.4,1,new taller2.utils.Point(4,0));
	}
	
	protected void createOptions(DrawingArea area,Graph graph, AlgorithmApplicator algorithmApplicator){
		options = new JComboBox<String>(Constants.availableOptions);
		options.setSelectedIndex(0);
		options.setBackground(new Color(0,0,0));
		options.addActionListener(new GraphCreatorMenuListener(area,graph, algorithmApplicator));
	}

		
    // unselects all buttons
    public void unselectButtons(){
    	applyChangesButton.setSelected(false);
    	saveGraphButton.setSelected(false);
    	loadGraphButton.setSelected(false);
    }  
}
